﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Helpers
{
    public static class ArrayEx
    {
        /// <summary>
        /// 输出数组全部元素.字符串格式为[a,b, ...]
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public static String ElementString(this Array arr){
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            for (int i = 0; i < arr.Length; i++)
            {
                sb.Append(arr.GetValue(i));
                if (i != arr.Length - 1)
                    sb.Append(",");
            }
            sb.Append("]");
            return sb.ToString();
        }

        public static bool ElementEquals(this Array arr, Array arr2)
        {
            if (arr == arr2)
                return true;
            if (arr.Length == arr2.Length)
            {
                int length = arr.Length;
                for (int i = 0; i < length; i++)
                {
                    object obj1 = arr.GetValue(i);
                    object obj2 = arr.GetValue(i);
                    
                    if (obj1.ToString() != obj2.ToString())
                        return false;
                }
            }
            return true;
        }
        
    }
}
